package com.izhang3.proxy.client;

import com.izhang3.proxy.channel.ChannelService;
import com.izhang3.proxy.config.ChannelTypeEnum;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.concurrent.CountDownLatch;

/**
 * @author 张良
 * @desc
 * @since 2019/6/20 14:17
 */
public class CrawlClientPool implements Runnable {

    private ChannelService channelService;

    private BaseParser baseParser;

    private CountDownLatch latch;

    public CrawlClientPool(BaseParser baseParser, ChannelService channelService, CountDownLatch latch) {
        this.baseParser = baseParser;
        this.channelService = channelService;
        this.latch = latch;
    }

    @Override
    public void run() {
        List<String> list = baseParser.parse();
        if (!CollectionUtils.isEmpty(list)) {
            channelService.addWaitList(list, ChannelTypeEnum.WAITING);
        }
        latch.countDown();
    }
}
